{% extends "main/base.html" %}
{% load static i18n %}
{% block title %}{% trans '添加组件' %}{% endblock %}
{% block content %}
{% if object %}
<div class="row">
    <aside class="profile-nav col-lg-3 alt green-border">
        <section class="panel">
            <div class="user-heading alt green-bg">
                <h1>{{ object.assembly_name }}</h1>
                {% if perms.main.view_equipment_basic_price %}<p>{% trans '部件成本' %}: {{ object.total_value }}</p>{% endif %}
            </div>
            <ul class="nav nav-pills nav-stacked">
                <li><a href="{% url 'main:equipment_assembly_detail' request.GET.a %}"><i class="fa fa-gear"></i> {% trans '组装详情' %} </a></li>
                {% if perms.main.change_equipmentassembly %}{% if object %}<li><a href="{% url 'main:equipment_als_update' request.GET.a %}"> <i class="fa fa-edit"></i> {% trans '编辑资料' %}  </a></li>{% endif %}{% endif %}
                <li class="active"><a href=""> <i class="fa fa-plus"></i> {% trans '添加部件' %}  </a></li>
            </ul>
        </section>
    </aside>
    <aside class="profile-info col-lg-9">
        <section class="panel">
            <div class="panel-heading">
                <h4 class="heading">{% trans '主设备名称' %}: <a href="">{{ object.equipment.equipment_cn|default_if_none:'N/A' }}/{{ object.equipment.equipment_en|default_if_none:'' }}</a></h4>
            </div>
            <div class="panel-body bio-graph-info">
                <div class="row">
                    <div class="bio-row">
                        <p><span>{% trans '备注' %}: </span>{{ object.notes }}</p>
                    </div>
                </div>
            </div>
        </section>
        {% if object.created_by_id == request.user.pk or request.user.pk in object.cooperators or request.user.is_staff %}
        <section class="panel">
            <header class="panel-heading">
                {% trans "添加组件" %} {% if form.errors %}<p>{% trans "您提交的数据有误,请认真检查!" %}</p>{% endif %}{{ form.non_field_errors }}
            </header>
            <div class="panel-body">
                <form method="post" class="form-horizontal" action="{% url 'main:assembly_item_create' %}?next={{ request.GET.next }}">{% csrf_token %}
                    <input type="hidden" name="equipment_assembly" id="id_equipment_assembly" value="{{ request.GET.a }}">
                    <div class="form-group">
                        <div class="col-lg-2">{{ form.equipment.label_tag }}</div>
                        <div class="col-lg-10">
                            <div class="input-group">
                                <input class="form-control" type="text" id="equipment_search" value="" placeholder="搜索设备" onchange="refreshBtn();">
                                <span class="input-group-btn"><label class="btn btn-primary" id="search_btn" onclick="loadXMLDoc();">搜索</label></span>
                            </div>
                        </div>
                        <div class="col-lg-offset-2 col-lg-10">
                            <select name="equipment" class="selectpicker form-control" data-live-search="true" required id="id_equipment">
                                <option value="" selected>---------</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-lg-2">{{ form.amount.label_tag }}</div>
                        <div class="col-lg-4">{{ form.amount }} {{ form.amount.errors }}</div>
                        <div class="col-lg-2">{{ form.order_index.label_tag }}</div>
                        <div class="col-lg-4">{{ form.order_index }} {{ form.order_index.errors }}</div>
                    </div>
                    <div class="form-group">
                        <div class="col-lg-2">{{ form.notes.label_tag }}</div>
                        <div class="col-lg-10">{{ form.notes }}{{ form.notes.errors }}</div>
                    </div>
                    <div class="form-group" align="right">
                        <div class="col-lg-12">
                            <button type="submit" class="btn btn-primary">{% trans "提交" %}</button>
                        </div>
                    </div>
                </form>
            </div>
        </section>
        {% endif %}
    </aside>
</div>
{% endif %}
{% endblock %}
{% block this_js %}
<script type="text/javascript" src="{% static 'flatlab/js/bootstrap-switch.js' %}"></script>
<script type="text/javascript" src="{% static 'main/js/load_equipment.js' %}"></script>
<script>
    window.onload = function(){
        document.getElementById("id_order_index").value={{ object.next_index }};
	}
</script>
{% endblock %}